home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 3d_lib.zip / ID.C < prev    next >
C/C++ Source or Header  |  1993-05-09  |  1KB  |  49 lines

  1. /* Create identity matrix
  2.  
  3.    Copyright (c) 1988 by Gus O'Donnell
  4.  
  5.    Revision history:
  6.  
  7.    Version 1.00         February 29, 1988       As released.
  8.  
  9.    Version 1.01         March 20, 1988          Created libraries for all
  10.                                                 memory models
  11.  
  12. */
  13. #include "3d.h"
  14. #include <float.h>
  15. #include <math.h>
  16. #include <stdio.h>
  17.  
  18. void    identity (MATRIX this_mat)
  19.  
  20. /* Initialize the transformation matrix to the identity matrix,
  21. i.e., all ones on the diagonal.  A matrix is initially created using
  22. the following code:
  23.  
  24.                    MATRIX example;
  25.                    identity (example);
  26.  
  27. The result is:
  28.  
  29.               |  1.0  0.0  0.0  0.0  |
  30.               |  0.0  1.0  0.0  0.0  |
  31.               |  0.0  0.0  1.0  0.0  |
  32.               |  0.0  0.0  0.0  1.0  |
  33.  
  34. A vertex multiplied by the identity matrix is unchanged.
  35. */
  36.  
  37. {
  38.     int ri,ci;/* Row and column counters */
  39.  
  40.     for (ri = 0; ri < RMAX; ri++)
  41.         for (ci = 0; ci < CMAX; ci++)
  42.             if (ri == ci)                 /* Row index == column index, so
  43.                                              set element to 1.0 */
  44.                 this_mat [ri] [ci] = 1.0;
  45.             else
  46.                 this_mat [ri] [ci] = 0.0; /* Otherwise, set off diagonals
  47.                                              to 0.0. */
  48. }
  49.